import {useAdminStore} from "@/store/admin";

export default {
    mounted(el: any, binding: any, vnode: any) {

        const {value} = binding
        const adminStore = useAdminStore()

        const hasPermissions = adminStore.rules.some(permission => {

            const permissionFlag = permission.toLowerCase()

            if (!value){
                throw new Error(`请设置操作权限标签值`)
            } else if (value instanceof Array && value.length > 0) {   // 传入数组

                return value.some(valueItem => {
                    return valueItem.toLowerCase() == permissionFlag
                })

            } else if (value == '*' || value.toLowerCase() == permissionFlag || adminStore.info.id == 1) {   // 传入字符串
                return true
            } else {
                return false
            }
        })

        if (!hasPermissions) {
            el.parentNode && el.parentNode.removeChild(el)
        }

    }
}
